package test.common.core.message;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import web.common.core.message.MessageDecoder;
import web.common.core.message.MessageEncoder;
import web.common.core.message.Serializable;

/**
 * @author Jin Zheng
 * @since 1.0 2022-02-11
 */
@Getter
@Setter
@AllArgsConstructor
public class User implements Serializable {
	private Integer id;
	private String name;
	private double score;

	public User() {
	}

	@Override
	public void encode(MessageEncoder encoder) {
		encoder.writeNumber(id);
		encoder.writeString(name);
		encoder.writeDouble(score);
	}

	@Override
	public void decode(MessageDecoder decoder) {
		this.id = decoder.readNumber(Integer.class);
		this.name = decoder.readString();
		this.score = decoder.readDouble();
	}
}
